package servlet;

import dao.Db;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/del")
public class DelOne extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws SecurityException, IOException, ServletException {
       this.doPost(req,resp);
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws SecurityException, IOException, ServletException {
        //获取删除的那条记录的主键ID
        String id=req.getParameter("id");
        System.out.println("id="+id);
        //数据访问层
        Db db=new Db();
        int i=db.del(id);
        System.out.println("i="+i);
        if (i>0){
            req.getRequestDispatcher("showlist").forward(req,resp);
        }else{
            System.out.println("删除失败");
        }
    }
}
